home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / RCTNGL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.1 KB  |  40 lines

  1.                                             /* rctngl.c   ( rectangle ) */
  2.                                  /* Entered by A. Wayner */
  3.  
  4. # include <graphics.h>
  5. # include <stdlib.h>
  6.  
  7. main()
  8. {
  9.     int graphdriver = DETECT;
  10.     int graphmode, x1, x2, y1, y2, maxx, maxy, maxcolor;
  11.  
  12.                                             /* Detect adapter type and    */
  13.                                             /* initialize graphics system */
  14.       initgraph( &graphdriver, &graphmode, "\\turboc");
  15.     outtextxy( 10, 10, "Random rectangles with 'rectangle' ");
  16.  
  17.     maxx = getmaxx() - 100;
  18.     maxy = getmaxy() - 60;
  19.     maxcolor = getmaxcolor();
  20.     randomize();                        /* Initialize random number generator */
  21.  
  22.                                             /* Exit when user presses a key */
  23.     outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
  24.     while( !kbhit())
  25.     {
  26.                                             /* Generate random points for the corners */
  27.         x1 = random( maxx ) + 50;
  28.         x2 = random( maxx ) + 50;
  29.         y1 = random( maxy ) + 30;
  30.         y2 = random( maxy ) + 30;
  31.         setcolor( LIGHTCYAN );
  32.  
  33.                                             /* Now draw the rectangle */
  34.         rectangle( min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2));
  35.     }
  36.  
  37.     closegraph();                        /* Exit graphics library */
  38.  
  39. }
  40.